package mspbots.autotask.client.core.app;

import lombok.RequiredArgsConstructor;
import mspbots.autotask.client.core.client.ClientProperties;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import javax.validation.Valid;
import java.util.Map;

/**
 * mspbots.core.autotask.core.app.AutoTaskController
 *
 * @author Alex bob(https://github.com/vnobo)
 * @date Created by 2020/7/8
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("client")
public class AutoTaskController {

    private final AutoTaskServiceImpl autoTaskServiceImpl;

    @DeleteMapping("{tenantId}")
    public Mono<Void> delete(@PathVariable Long tenantId) {
        return this.autoTaskServiceImpl.delete(tenantId);
    }

    @PostMapping("test")
    public Mono<Boolean> testClient(@Valid @RequestBody ClientProperties params) {
        return this.autoTaskServiceImpl.initialize(params);
    }

    @GetMapping("synchronise/{tenantId}")
    public Flux<Map<String, Boolean>> synchronise(@PathVariable Long tenantId) {
        return autoTaskServiceImpl.synchronise(tenantId);
    }

    @GetMapping("on-off/{tenantId}/{onOff}")
    public Mono<Boolean> onOff(@PathVariable Long tenantId, @PathVariable String onOff) {
        return autoTaskServiceImpl.onOffTenant(tenantId, onOff);
    }
}
